
class ObjUtils {

    static isObj(obj) {
        return (typeof obj === 'object' || typeof obj === 'function') && obj !== null;
    }

    static deepCopy(obj, hash = new WeakMap()) {
        let cloneObj;
        let Constructor = obj.constructor;
        switch (Constructor) {
            case RegExp:
                cloneObj = new Constructor(obj);
                break
            case Date:
                cloneObj = new Constructor(obj.getTime());
                break
            default:
                if (hash.has(obj)) return hash.get(obj);
                cloneObj = new Constructor();
                hash.set(obj, cloneObj);
        }
        for (let key in obj) {
            cloneObj[key] = this.isObj(obj[key]) ? this.deepCopy(obj[key], hash) : obj[key];
        }
        return cloneObj;
    }
}

export {
    ObjUtils
}